package com.travelsmart.client.apresentacao.view.subview;

import java.util.List;

import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.travelsmart.client.apresentacao.view.BaseView;
import com.travelsmart.client.apresentacao.widget.FormImagePopupPanel;
import com.travelsmart.client.bean.to.HotelTO;

//# EXERC. 4 TODO: Exercicio 4
public class ViewImagensHotel extends BaseView{
	private final VerticalPanel vPanelViewImagensHotel = new VerticalPanel();
	public ViewImagensHotel(){
		super(new HTML());
		initWidget(vPanelViewImagensHotel);
	}
	
	public void exec(final HotelTO hotel){
		vPanelViewImagensHotel.clear();
		vPanelViewImagensHotel.add(geraGridImagensHotel(hotel));
	}
	
	private Grid geraGridImagensHotel(final HotelTO hotel) {
		List<String> imagens = hotel.getListImages();
		int numColuna = 10;
		int numLinha = imagens.size() / numColuna;
		if(imagens.size() % numColuna != 0){
			numLinha++;
		}
		 // Create a grid
	    Grid grid = new Grid(numLinha, numColuna);

	    // Add images to the grid
	    int numRows = grid.getRowCount();
	    int numColumns = grid.getColumnCount();
	    int index = 0;
	    for (int row = 0; row < numRows; row++) {
	      for (int col = 0; col < numColumns; col++) {
	    	  if(index < imagens.size()){
	    		  grid.setWidget(row, col, new FormImagePopupPanel(imagens.get(index++)));	  
	    	  }else{
	    		  break;
	    	  }
	        
	      }
	    }
		return grid;
	}
}